package com.qzy.reggie.mapper;

import com.qzy.reggie.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MealMapper {

      @Select("select  * from setmeal" )



//    @Select("<script>select d.id,d.name,d.category_id categoryId,d.price,code,d.image,d.description,d.status,d.is_deleted isDeleted,d.create_time createTime,d.update_time updateTime,d.create_user createUser,d.update_user updateUser " +
//            ", c.name categoryName " +
//            "from setmeal d left join setmeal c on d.category_id = c.id " +
//            "<where> " +
//            "<if test='name!=null'> d.name like '${name}%'</if>" +
//            "</where>" +
//            "</script>")
      List<Setmeal> selectList(String name);

    @Select("<script>select * from setmeal " +
            "<where> " +
            "<if test='id != null'> and id=#{id}</if>" +
            "</where>" +
            "</script>")
    Setmeal selectOne(Setmeal setmeal);


//    @Insert("insert into setmeal (name,category_id,price,code,image,description,create_time,update_time,create_user,update_user) values (#{name},#{categoryId},#{price},#{code},#{image},#{description},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
//    Integer insert(Setmeal setmeal);

    @Insert("insert into setmeal (name,category_id,price,code,image,description,sort,create_time,update_time,create_user,update_user) values (#{name},#{categoryId},#{price},#{code},#{image},#{description},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer insert(Setmeal setmeal);
    @Update("<script>" +
            "update setmeal <set>" +
            "<if test='name !=null'>name=#{name},</if>" +
            "<if test='categoryId !=null'>category_id=#{categoryId},</if>" +
            "<if test='price !=null'>price=#{price},</if>" +
            "<if test='image !=null'>image=#{image},</if>" +
            "<if test='description !=null'>description=#{description},</if>" +
            "<if test='updateTime !=null'>update_time=#{updateTime},</if>" +
            "<if test='updateUser !=null'>update_user=#{updateUser},</if>" +
            "</set>" +
            "where id=#{id}" +
            "</script>")
    Integer update(Setmeal setmeal);

    @Delete("delete from setmeal where id = #{id}")
    Integer delete(Long id);
}
